#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtGui>
#include "gamedata.h"
#include "menulabel.h"
#include "menulineedit.h"
#include "menuselecter.h"
#include "menucombobox.h"

#define BASE_FRAME 12

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

    private:
        Ui::MainWindow *ui;

        int centerX, centerY;
        int centerTileX, centerTileY; // top right of center tile

        int currentView;
        bool inGame;
        enum views {MainMenu, NewGame, LoadGame, Settings, InGame, Paused};
        Sound *gameMusic;

        Map *curMap;
        Player *player;
        int origX, origY;

        bool cheatMode;
        QString cheatString;

        QTimer *animTimer;
        int curFrame;

        // game methods
        void loadUserAndStart(QString username);
        void switchMaps(QString newMapName, int linkCode);
        void playerMoved();

        // overridden event methods
        void paintEvent(QPaintEvent *);
        void mousePressEvent(QMouseEvent *);
        void keyPressEvent(QKeyEvent *);
        void focusOutEvent(QFocusEvent *);
        void closeEvent(QCloseEvent *);

        // main menu view
        void setUpMainMenuWidgets();
        void showMainMenuWidgets();
        void hideMainMenuWidgets();
        MenuLabel *lblNewGame;
        MenuLabel *lblLoadGame;
        MenuLabel *lblMainSettings;
        MenuLabel *lblExit;

        // new game view
        void setUpNewGameWidgets();
        void showNewGameWidgets();
        void hideNewGameWidgets();
        MenuLineEdit *txtUserName;
        MenuSelecter *selDifficulty;
        MenuLabel *lblStartGame;
        MenuLabel *lblBackFromNew;

        // load game view
        void setUpLoadGameWidgets();
        void showLoadGameWidgets();
        void hideLoadGameWidgets();
        MenuComboBox *boxNameSelect;
        MenuLabel *lblLoadAndStart;
        MenuLabel *lblBackFromLoad;

        // settings view
        void setUpSettingsWidgets();
        void showSettingsWidgets();
        void hideSettingsWidgets();
        MenuSelecter *selSoundEnabled;
        MenuSelecter *selMusicEnabled;
        MenuLabel *lblBackFromSettings;

        // paused game view
        void setUpPausedGameWidgets();
        void showPausedGameWidgets();
        void hidePausedGameWidgets();
        MenuLabel *lblResumeGame;
        MenuLabel *lblPausedSettings;
        MenuLabel *lblSaveAndExit;

    private slots:
        // main menu view slots
        void newGame_clicked();
        void loadGame_clicked();
        void mainSettings_clicked();
        void exit_clicked();

        // new game view slots
        void startGame_clicked();
        void backFromNew_clicked();

        // load game view slots
        void loadAndStart_clicked();
        void backFromLoad_clicked();

        // settings view slots
        void soundEnabled_changed(QString newSelection);
        void musicEnabled_changed(QString newSelection);
        void backFromSettings_clicked();

        // paused game view slots
        void resumeGame_clicked();
        void pausedSettings_clicked();
        void saveAndExit_clicked();

        // other
        void animTimerFire();
};

#endif // MAINWINDOW_H
